#include "Timer.h"
#include <iostream>

using std::cout;
using std::endl;
using std::cerr;

Timer::Timer(int64_t timerId, 
             std::chrono::steady_clock::time_point expireTime,
             std::chrono::milliseconds interval,
             TimerCallback &&callback)
: _timerId(timerId)
, _expireTime(expireTime)
, _interval(interval)
, _callback(std::move(callback))
{
}

void Timer::run()
{
    if (_callback) {
        _callback();
    }
}

void Timer::restart()
{
    if (isRepeated()) {
        _expireTime = std::chrono::steady_clock::now() + _interval;
    }
}